package com.lotus.lqmp.service.facade;

import com.lotus.lqmp.service.common.annotations.CostTimeRecord;
import com.lotus.platform.common.model.base.BaseResult;
import com.lotus.platform.common.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 使用restTemplate通过域名/ip调用外部第三方接口的防腐层
 * CostTimeRecord注解统计耗时
 * @author Liwei.Zhang3
 * @since 2022/01/18 17:46
 */
@Slf4j
@Service
@CostTimeRecord
public class XXXFacade {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${xxx.url:http://xxx/a/b/c}")
    private String xxxUrl;

    public String test(String input) {
        try {
            BaseResult<String> result = restTemplate.getForObject(xxxUrl, BaseResult.class);
            if (result.isSuccess()) {
                return CommonUtils.unWrapper(result);
            } else {
                log.error("test fail {}", result);
                // do something
            }
        } catch (Exception e) {
            log.error("test error", e);
        }
        return "";
    }
}
